#!/usr/bin/env ruby
# coding: utf-8

load 'config.rb',true
require 'rubygems'
require 'json'
require 'TwitterClass'

#require 'oauth-patch' #Ruby1.9以上の人

twitter = TwitterClass.new($config[:CONSUMER_KEY],$config[:CONSUMER_SECRET],$config[:ACCESS_TOKEN],$config[:ACCESS_TOKEN_SECRET],$config[:TWITPIC_API_KEY])

#p twitter.post_twitpic_basic($config[:MY_NAME],$config[:PASSWD],'image/test2.jpg','test update')
p twitter.twitpic_upload('image/test.jpg','アップロードのテスト')

#twitter.follow('timer')

#仕様上、半日以内に同じ文字を送ると失敗するはず
=begin
if (twitter.update("Test")) then
	puts "success to tweet"
else
	puts "con not tweet"
end
=end

#jpg/png/gifで700KB以内のファイルはうぷできるらしい
#p twitter.change_profile_image('image/test.jpg')

=begin
##timelineの取得
count=0
puts "---- get timeline ----"
statuses = twitter.get_timeline()
begin
	if (statuses!=nil) then
		JSON.parse(statuses.body).reverse_each do |status|
				latestTW=status['id']
				count += 1
				twitter.dump_status_data(status) if(status!=nil)
		end
	end
rescue JSON::ParserError
	time = Time.now.strftime("%Y/%m/%d %H:%M:%S")
	puts "#{time}\t[Error:TL] cannot parse json"
end
puts "---- All #{count} stasuses  ----\n\n"
=end

=begin
count=0
puts "---- get direct messages ----"
messages = twitter.get_directmessage()
begin
	if (messages!=nil) then
		JSON.parse(messages.body).reverse_each do |message|
			count +=1
			twitter.dump_directmessage_data(message) if(message!=nil)
		end
	end
rescue JSON::ParserError
	time = Time.now.strftime("%Y/%m/%d %H:%M:%S")
	puts "#{time}\t[Error:DM] cannot parse json"
end
puts "---- All #{count} messages  ----\n\n"

count=0
puts "---- get friends ----"
users = twitter.get_friends
begin
	if (users!=nil) then
		JSON.parse(users.body).reverse_each do |user|
		count += 1
		twitter.dump_user_data(user) if(user!=nil)
	end
rescue JSON::ParserError
	time = Time.now.strftime("%Y/%m/%d %H:%M:%S")
	puts "#{time}\t[Error:DM] cannot parse json"
end
puts "---- All #{count} friends  ----\n\n"

=end

#twitter.favorite(15693845281)
#twitter.retweet(15693582234)
